﻿using Abp.BackgroundJobs;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Castle.Core.Logging;
using FwProject.ShoppingMall.Com;
using System;
using System.Collections.Generic;
using System.Text;

namespace FwProject.BackGround.ShopProductShip
{
    public class ShopShipBackground : BackgroundJob<BasArg>, ITransientDependency
    {
        private readonly IRepository<ShopOrderDetails, Guid> _repositoryShopOrderDetails;
        public ILogger logger { get; set; }
        public ShopShipBackground(IRepository<ShopOrderDetails, Guid> repositoryShopOrderDetails)
        {
            _repositoryShopOrderDetails = repositoryShopOrderDetails;
            logger = NullLogger.Instance;
        }

        [UnitOfWork]
        public override void Execute(BasArg args)
        {
            try
            {
                using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
                {
                    var detail = _repositoryShopOrderDetails.Get(args.Id);
                    if (detail.DeliveryStatus == DeliveryStatus.已发货)
                    {
                        detail.DeliveryStatus = DeliveryStatus.已确认;
                        _repositoryShopOrderDetails.Update(detail);
                    }

                    CurrentUnitOfWork.SaveChanges();
                }
            }
            catch (Exception exe)
            {

                logger.Error("后台延迟任务导致任务失败", exe);
            }
         
        }
    }
}
